#include <iostream>
#include "vec3d.h"
using namespace osg;

class MassPt
{
public:
	MassPt()
	{
		mId = -1;
		mM = 10.0;
		mS.set(0, 0, 0);
		mV.set(0, 0, 0);
		mF.set(0, 0, 0);
	}
	MassPt(int id, double m, Vec3d s, Vec3d v, Vec3d f) :
		mId(id), mM(m), mS(s), mV(v), mF(f)
	{

	}

	int mId; // id
	double mM;
	Vec3d mS; // position
	Vec3d mV; // velocity
	Vec3d mF; // force
};

void verlet_step(MassPt& p, double dt)
{
	MassPt t;
	p.mS = p.mS + p.mV * dt + p.mF * ((dt * dt) / (2.0 * p.mM));
	p.mV = p.mV + p.mF * (dt / p.mM);
}

void cout_state(MassPt& p, double t)
{
	std::cout << "time:" << t << ", ";
	std::cout << "pos: (" << p.mS.x() << ", " << p.mS.y() << ", " << p.mS.z() << ")" << ";\n";
}

void vertlet_test0()
{
	MassPt a(0, 10.0, Vec3d(0, 0, 0), Vec3d(20, 0, 0), Vec3d(0, -98, 0));

	double dt = 0.1;
	double t = 0.0;

	cout_state(a, t);

	for (size_t i = 0; i < 50; i++)
	{
		verlet_step(a, dt);
		t += dt;

		cout_state(a, t);
	}
}

int main()
{
	vertlet_test0();
	system("pause");
	return 0;
}